import socket
from bdtime import tt
from utils import coding_type, decode
from bdtime import tt

server_addr = ('192.168.2.12', 8080)

def send_file_to_client(new_client_socket, client_addr):
    file_name = new_client_socket.recv(1024).decode('utf-8')
    print(f'客户端({client_addr})要下载的文件是: ({file_name})')

    file_content = None

    with open(file_name, 'rb') as f:
        file_content = f.read()

    if file_content:
        new_client_socket.send(file_content)

    return 1

def main():
    tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    tcp_server_socket.bind(server_addr)
    tcp_server_socket.listen(128)
    print('--- server开启... ---')

    new_client_socket, client_addr = tcp_server_socket.accept()

    send_file_to_client(new_client_socket, client_addr)

    new_client_socket.close()
    tcp_server_socket.close()

if __name__ == '__main__':
    main()